package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class D_2024D_2607__栈火星文计算2 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			String str = sc.next();
			System.out.print(getResult(str));
		}

		public static long getResult(String str) {
			Pattern p = Pattern.compile("(\\d+)#(\\d+)");

			while (true) {
				Matcher m = p.matcher(str);
				if (!m.find()) break;

				String subStr = m.group(0);
				long x = Long.parseLong(m.group(1));
				long y = Long.parseLong(m.group(2));
				str = str.replaceFirst(subStr, 4 * x + 3 * y + 2 + "");
			}

			return Arrays.stream(str.split("\\$"))
				.map(Long::parseLong)
				.reduce((x, y) -> 2 * x + y + 3)
				.orElse(0L);
		}
	}